package builder

import "fmt"

//产品角色
type Product struct {
	partA string
	partB string
	partC string
}

func (self *Product)SetPartA(partA string)  {
	self.partA = partA
}
func (self *Product)SetPartB(partB string)  {
	self.partB = partB
}
func (self *Product)SetPartC(partC string)  {
	self.partC = partC
}
func (self *Product)Show()  {
	fmt.Printf("partA = %s ,partB = %s , partC = %s ",self.partA,self.partB,self.partC)
}

//抽象建造者
type Builder interface {
	builderPartA()
	builderPartB()
	builderPartC()
	getResult() Product
}


//具体建造者
type ConcreteBuilder1 struct {
	product Product
}

func (self *ConcreteBuilder1)builderPartA()  {
	self.product.SetPartA("a")
}
func (self *ConcreteBuilder1)builderPartB()  {
	self.product.SetPartB("b")
}
func (self *ConcreteBuilder1)builderPartC()  {
	self.product.SetPartC("c")
}
func (self *ConcreteBuilder1)getResult() Product {
	return self.product
}

//具体建造者
type ConcreteBuilder2 struct {
	product Product
}

func (self *ConcreteBuilder2)builderPartA()  {
	self.product.SetPartA("A")
}
func (self *ConcreteBuilder2)builderPartB()  {
	self.product.SetPartB("B")
}
func (self *ConcreteBuilder2)builderPartC()  {
	self.product.SetPartC("C")
}
func (self *ConcreteBuilder2)getResult() Product {
	return self.product
}


//指挥者
type Director struct {
	builder Builder
}

func NewDirector(builder Builder) *Director {
	return &Director{builder:builder}
}

func (self *Director)construct() Product{
	self.builder.builderPartA()
	self.builder.builderPartB()
	self.builder.builderPartC()
	return self.builder.getResult()
}

